package com.example.Wcf;

import java.util.Dictionary;
import java.util.Enumeration;
import org.json.JSONException;
import org.json.JSONObject;

 class ConverObjectToJsonString {
	
	 JSONObject GetJsonFromObject(JSonFactory jSonFactory,String key) throws IllegalArgumentException, JSONException, IllegalAccessException
	{
		
		JSONObject jsonObject=new JSONObject();
		jsonObject.put(key, jSonFactory.toJson());
		return jsonObject;
		
	}
	 String GetJsonFromString(String key,String value) throws JSONException
	{
		JSONObject jsonObject=new JSONObject();
		jsonObject.put(key, value);
		return jsonObject.toString();
		
	}
	 String GetJsonFromString(Dictionary<String, String>values) throws JSONException
	{
		JSONObject jsonObject=new JSONObject();
		Enumeration<String>keys=values.keys();
		while (keys.hasMoreElements()) {
			
			String key=keys.nextElement();
			jsonObject.put(key, values.get(key));
		}
		return jsonObject.toString();
		
	}
	 String  GetJsonFromObject(Dictionary<String, String>values,Dictionary<String, JSonFactory>objects) throws JSONException, IllegalArgumentException, IllegalAccessException
	{
		
		JSONObject jsonObject=new JSONObject();
		Enumeration<String>keys=values.keys();
		while (keys.hasMoreElements()) {
			
			String key=keys.nextElement();
			jsonObject.put(key, values.get(key));
		}
		
		keys=objects.keys();
		 
			
		  while (keys.hasMoreElements()) 
		  {
			  String keyString=keys.nextElement();
			JSonFactory s=objects.get(keyString);
			
			JSONObject valueString = null;
			
			valueString = GetJsonFromObject(s, keyString);
				jsonObject.put(keyString,valueString);
		}
		  return jsonObject.toString();
		
	}
	 
	 String GetJsonFromObject(Dictionary<String, JSonFactory>list) throws IllegalArgumentException, JSONException, IllegalAccessException
	{
		  Enumeration<String>keys=list.keys();
		  JSONObject jsonObject=new JSONObject();
			
		  while (keys.hasMoreElements()) 
		  {
			  String keyString=keys.nextElement();
			JSonFactory s=list.get(keyString);
			
			JSONObject valueString = null;
			
			valueString = GetJsonFromObject(s,keyString);
				jsonObject.put(keyString,valueString);
			
		}
		 return jsonObject.toString();
		
		
		
	}

}
